#pragma once

#include "MessageFwd.h"
#include "GalconCommonTypes.h"
#include "PlanetInternalImpl.h"
#include <map>
#include "GameState.h"
#include "MessageBuilder.h"

class GameStateAccessor
{

public:
   
   GameStateAccessor(unsigned int countOfPlanets, unsigned int countOfPlayers);
   
   ~GameStateAccessor();
   
   // creates message of current game state
   MessagePtr GetGameStateMsg() const
   {
      return MessageBuilder::BuildGameStateMessage(m_gameStatePtr);
   }
   
   MessagePtr GetInitialGameStateMsg(PlayerID playerID, GameColors playerColor) const
   {
      return MessageBuilder::BuildGameStateInitialMessage(m_gameStatePtr, playerID, playerColor);
   }

   void SetShipCount(PlanetID planetID, double count) const
   {
      m_gameStatePtr->SetShipCount(planetID, count);
   }

   double GetShipCount(PlanetID planetID) const
   {
      return m_gameStatePtr->GetShipCount(planetID);
   }

   void AddShipCountOnPlanet(PlanetID planetID, int countOfShips, PlayerID srcPlayerID)
   {
      m_gameStatePtr->SetShipCount(planetID, m_gameStatePtr->GetShipCount(planetID) + countOfShips);
   }

   GameColors GetPlayerColor(PlayerID playerID) const
   {
      return m_gameStatePtr->GetPlayerColor(playerID);
   }

   void SetPlanetOwnerID(PlanetID planetID, PlayerID playerID)
   {
      PlanetInternalImplPtr planet = m_gameStatePtr->GetPlanet(planetID);
      planet->SetPlayerID(playerID);
   }

   // updates count of ships on planets
   void UpdatePlanets() const
   {
      m_gameStatePtr->UpdatePlanets();
   }
private:
   void init();
   GameStatePtr m_gameStatePtr;
   const unsigned int m_countOfPlanets;
   const unsigned int m_countOfPlayers;
};

typedef boost::shared_ptr<GameStateAccessor> GameStateAccessorPtr;